package com.cdtye.itps.cms.service.origindata;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cdtye.common.mybatiscore.base.BaseService;
import com.cdtye.itps.cms.dao.enums.CommonFileType;
import com.cdtye.itps.cms.dao.origindata.entity.JcjcDetectC1Data;
import com.cdtye.itps.cms.dao.origindata.vo.JcjcDetectC1DataVo;
import com.cdtye.itps.cms.mapper.origindata.JcjcDetectC1DataMapper;
import com.cdtye.itps.cms.mapper.origindata.JcjcDetectC1JobMapper;
import com.cdtye.itps.cms.util.ExpCommonHelper;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class JcjcDetectC1DataService extends BaseService<JcjcDetectC1DataMapper, JcjcDetectC1Data> {

    @Autowired
    private JcjcDetectC1JobMapper detectC1JobMapper;

    public IPage<JcjcDetectC1Data> listPage(JcjcDetectC1DataVo vo){
        return baseMapper.listPage(vo.page(),vo);
    }

    public void exportC1Data(JcjcDetectC1DataVo vo, HttpServletResponse response){
        Map<String,Object> job = detectC1JobMapper.selectDetail(vo.getDetectJobId());
        if (job!=null) {
            StringBuilder str = new StringBuilder();
            str.append(job.get("seclineName").toString()).append("-").append(job.get("directionName").toString()).append("-");
            if (job.get("startSiteName")!=null) {
                str.append(job.get("startSiteName").toString()).append("-");
            }
            if (job.get("endSiteName")!=null) {
                str.append(job.get("endSiteName").toString()).append("-");
            }
            str.append(job.get("detectDate").toString());
            List<JcjcDetectC1Data> datas = baseMapper.hisList(vo);
            Workbook workbook = null;
            List<List<String>> exportExcels = new ArrayList<>();
            datas.forEach(i -> {
                if (i.getRoadMark()!=null) {
                    List<String> exportExcel = new ArrayList<>();
                    exportExcel.add(i.getPillarNum());
                    exportExcel.add(i.getRoadMark()+"");
                    exportExcel.add(i.getRoadMark()+"");
                    exportExcel.add(i.getGuideHeight1() + "");
                    exportExcel.add(i.getStaggers1() + "");
                    exportExcel.add(i.getHardPoint() + "");
                    exportExcel.add(i.getStress() + "");

                    exportExcels.add(exportExcel);
                }
            });

            workbook = ExpCommonHelper.exportStaticsData(exportExcels, new ArrayList<>(), CommonFileType.DETECT_C1DATA);

            ExpCommonHelper.exportCommonMethodNew(workbook, response, str.toString());
        }



    }
}
